define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/houseout/index',
                    multi_url: 'store/houseout/multi',
                    table: 'houseout',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',

                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_id', title: "出库单号"},
                        {field: 'type', title: __('Type'), searchList: {"1":"采购退货出库","2":"盘亏出库","3":"调拔出库","4":"要货出库","5":"销售出库","6":"其他出库","7":'采购作废订单'}, formatter: Table.api.formatter.normal},
                        {field: 'cid', title: __('Cid')},
                        {field: 'inputtime', title: __('Inputtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        {field: 'publisher', title: __('Publisher')},
                        {
                            field: 'operate',
                            width: "120px",
                            title: '查看订单',
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    title: __('查看订单'),
                                    text: __('查看订单'),
                                    classname: 'btn btn-primary btn-success btn-detail btn-dialog',
                                    icon: 'fa fa-camera',
                                    url: 'store/houseout/view',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});